package ecomm.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;

@Data
@TableName("users")          // 表名统一用复数
public class User {

    @TableId(type = IdType.AUTO)
    private Long id;

    @TableField(value = "username")
    private String username;

    @TableField(value = "email")
    private String email;

    @TableField(value = "password")
    private String password;

    @TableField(value = "status")   // 0:禁用  1:正常
    private Integer status;

    @TableLogic(value = "0", delval = "1")
    @TableField(value = "deleted")
    private Integer deleted = 0;

    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime = LocalDateTime.now();

    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime = LocalDateTime.now();

    /* --------------- 非表字段 --------------- */

    // 用户当前所有角色（联表查询用）
    @TableField(exist = false)
    private List<Role> roles;

    // 行为方法，可按需扩展
    public void register() { /* 注册逻辑 */ }
    public boolean login()  { /* 登录校验 */ return true; }
    public void update()    { /* 更新资料 */ }
}

//package ecomm.entity;
//
//import com.baomidou.mybatisplus.annotation.*;
//import lombok.Data;
//import java.time.LocalDateTime;
//
//@Data
//@TableName("users")
//public class User {
//    @TableId(type = IdType.AUTO)
//    private Long id;
//
//    private String username;
//    private String password;
//    private String email;
//    private Integer status;
//
//    @TableLogic
//    private Integer deleted;
//
//    @TableField(fill = FieldFill.INSERT)
//    private LocalDateTime createTime;
//
//    @TableField(fill = FieldFill.INSERT_UPDATE)
//    private LocalDateTime updateTime;
//}